<?php
!defined('P_W') && exit('Forbidden');
require_once M_P.'lib/base/typedatabbs.class.php';
class PW_TypeDataGroup extends PW_TypeDataBBS {
	var $_db;
	function __construct() {
		global $db;
		$this->_db = $db;
	}
	function PW_TypeDataGroup() {
		$this->__construct();
	}
	
	function _getDataFromBBS($hid,$count) {
		$cyid = $this->_db->get_value('SELECT cyid FROM pw_house_info WHERE hid='.pwEscape($hid));
		if (!$cyid) return array();
		return $this->_getGroupNewReply($cyid,$count);
	}
	
	function _getGroupNewReply($cyid,$num) {
		$tids = $this->_getTidsByCyid($cyid,$num);
		if (!$tids) return array();
		$temp = array();
		$rs = $this->_db->query('SELECT tid,fid,author,subject,postdate FROM pw_threads WHERE tid IN('.pwImplode($tids).')');
		while ($rt = $this->_db->fetch_array($rs)) {
			$temp[] = $this->_initData($rt);
		}
		return $temp;
	}
	
	function _getTidsByCyid($cyid,$num) {
		$temp = array();
		$rs = $this->_db->query('SELECT tid FROM pw_argument WHERE cyid='.pwEscape($cyid).' ORDER BY lastpost DESC '.pwLimit(0,$num));
		while ($rt = $this->_db->fetch_array($rs)) {
			$temp[] = $rt['tid'];
		}
		return $temp;
	}

}
?>